import Qt 4.7

Rectangle {


    function updateSyncProgress(cur, total) {
        syncPercentInt = cur / total * 100;
        syncPercentString = syncPercentInt + "%";
    }

    property bool inPortrait: false
    property string statusText: "Offline"
    property string syncPercentString: ""
    property int    syncPercentInt: 0

    id: mainviewwidget
    width: (inPortrait)? 450 : 800
    height: (inPortrait)? 800 : 450
    color: "white"

    signal newNoteClicked
    signal allNotesClicked
    signal notebooksClicked
    signal tagsClicked
    signal cameraClicked
    signal searchesClicked

    Rectangle {
        id: statusbar
        color: "#88be67"
        width: parent.width
        height: (inPortrait)? 75 : 38
        anchors.bottom: parent.bottom

        Text {
            id: statusbartext
            color: "white"
            font.family: "Nokia Sans"
            font.pixelSize: (inPortrait)? 20 : 18
            text: statusText + " " + syncPercentString
            smooth: true
            y: (inPortrait)? parent.height / 2 - paintedHeight / 2 - 12 : parent.height / 2 - paintedHeight / 2
            x: 12
        }

        BorderImage {
            id: syncbar
            x: (inPortrait)? 12 : statusbartext.width + statusbartext.x + 12
            y: (inPortrait)? parent.height / 2 + height / 2 + 6 : parent.height / 2 - height / 2
            width: (inPortrait)? 456 : statusbar.width - x - 12
            border { left: 6; top: 0; right: 6; bottom: 12 }
            horizontalTileMode: BorderImage.Repeat
            source: "../IconAdd/9patch_syncbar_bkgd.9.png"
        }

        BorderImage {
            id: syncbarprogress
            source: "../IconAdd/9patch_syncbar_fill.9.png"
            width: syncPercentInt * syncbar.width / 100
            height: 12
            border { left: 6; top: 0; right: 6; bottom: 12 }
            horizontalTileMode: BorderImage.Repeat
            x: (inPortrait)? 12 : statusbartext.width + statusbartext.x + 12
            y: (inPortrait)? parent.height / 2 + height / 2 + 9 : parent.height / 2 - height / 2 + 1
        }
    } // Statusbar

    /* Top bar */
    Rectangle {
        id: topbar
        x: 0
        y: 0
        width: parent.width
        height: (inPortrait)? 60 : 38

        BorderImage {
            id: topbarbg
            source: "../IconAdd/9patch_grn_hdr_port.9.png"
            width: parent.width;
            height: parent.height
            border { left: 1; top: 0; right: 1; bottom: 0 }
            x: parent.x

            Image {
                id: logo
                source: (inPortrait)? "../IconAdd/btn_full_logo_port_default.png" : "/IconAdd/logo_full_land_default.png"
                x: parent.x
                //fillMode: Image.PreserveAspectFit
                smooth: true
                anchors.bottom: parent.bottom
                anchors.top: parent.top
            }
        }
    }

    Rectangle {
        id: iconList
        height: (inPortrait)? parent.height - topbar.height - statusbar.height - 76*2 : parent.height - topbar.height - statusbar.height - 38 - 76;

        property int hspace: (inPortrait)? 128 / 2 : (parent.width - 100*3) / 3
        property int vspace: (inPortrait)? (height - 100*3) / 3 : 128 / 2
        y: (inPortrait)? topbar.height + 76 : topbar.height + 38
        x: 76/*(inPortrait)? 76 : parent.width - 100*3 - hspace*3*/
        width: (inPortrait)? parent.width - x*2 : parent.width - x*3
        MainViewIcon {
            onClicked: newNoteClicked
            iconId: "newnote"; iconSource: "../IconAdd/btn_newnote"; textString: "New note" }

        MainViewIcon {
            x: (inPortrait)? 0 : 100 + parent.hspace
            y: (inPortrait)?  110 + parent.vspace : 0
            onClicked: allNotesClicked
            iconId: "allnotes"; iconSource:  "../IconAdd/btn_allnotes"; textString: "All notes (0)" }


        MainViewIcon {
            x: (inPortrait)? parent.width - 100 : 100*2 + parent.hspace*2
            y: (inPortrait)? 110 + parent.vspace : 0
            onClicked: tagsClicked
            iconId: "tags"; iconSource:  "../IconAdd/btn_tags"; textString: "Tags (0)" }


        MainViewIcon {
            x: (inPortrait)? parent.width - 100 : 0
            y: (inPortrait)? 0 : 110 + parent.vspace
            onClicked: cameraClicked
            iconId: "snapshot"; iconSource:  "../IconAdd/btn_camera"; textString: "Snapshot" }


        MainViewIcon {
            x: (inPortrait)? 0 : 100 + parent.hspace
            y: (inPortrait)? 110*2 + parent.vspace*2 : 110 + parent.vspace
            onClicked: notebooksClicked
            iconId: "notebooks"; iconSource:  "../IconAdd/btn_notebooks"; textString: "Notebooks" }


        MainViewIcon {
            x: (inPortrait)? parent.width - 100 : 100*2 + parent.hspace*2
            y: (inPortrait)? 110*2 + parent.vspace*2 : 110 + parent.vspace
            onClicked: searchesClicked
            iconId: "searches"; iconSource:  "../IconAdd/btn_searches"; textString: "Searches" }


    }

    Image {
        source: (inPortrait)? "../IconAdd/ic_drawnline_port.png" : "../IconAdd/ic_drawnline_land.png"
        x: (inPortrait)? 76 : iconList.x + 100 + iconList.hspace / 3
        y: (inPortrait)? iconList.y + 110 + iconList.vspace / 2 : iconList.y
        height: (inPortrait)? 2 : 278
        width: (inPortrait)? 328 : 2
    }
}

